package com.wisezone.HomeWork.home0218;

import com.wisezone.demo0218.Person;

import java.lang.annotation.Annotation;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

//2.获取泛型的父类

public class Test01 {
    public void test01() throws Exception{
        Class clazz = Person.class;
        Type type = clazz.getGenericSuperclass();
        System.out.println(type);
    }

    //1.获取运行时类的父类
    public void Test02() throws Exception{
        Class clazz = Person.class;
        Class parent = clazz.getSuperclass();
        System.out.println(parent);
    }
    //4.获取实现的接口
    public void test04() throws Exception{
        Class clazz = Person.class;
        Class[] infaces = clazz.getInterfaces();
        for (Class class1 : infaces){
            System.out.println(class1);
        }
    }

    //3.获取父类的泛型
    public void test3() throws  Exception{
        Class clazz = Person.class;
        Type type = clazz.getGenericSuperclass();
        //强转成子接口
        ParameterizedType param = (ParameterizedType)type;
        Type[] types = param.getActualTypeArguments();
        //向下转型
        System.out.println(((Class) types[0]).getName());
    }

    //6.获取注解
    public void test6() throws Exception{
        Class clazz = Person.class;
        Annotation[] anns =  clazz.getAnnotations();
        for(Annotation annotation : anns){
            System.out.println(annotation);
        }
    }

    //5.获取所在包
    public void test5() throws  Exception{
        Class  clazz = Person.class;
        Package packages = clazz.getPackage();
        System.out.println(packages);
    }

}